﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Xml.Serialization;

namespace SDL
{
    [Serializable]
    public class DBObject : ORM
    {
        [XmlIgnore]
        public readonly Dictionary<string, object> Fields = new Dictionary<string, object>();

        [XmlIgnore]
        public Dictionary<string, object> ReadFields { get; set; }

        [XmlIgnore]
        public bool ReadFromCache { get; internal set; }

        [XmlIgnore]
        public bool ReadFromDb { get; internal set; }

        public override void Run(string sCommand, CommandType cmdType, bool putObjectParams)
        {
            base.Run(sCommand, cmdType, putObjectParams);
            Fields.Clear();
        }

        public override object Scalar(string sCommand, CommandType cmdType, bool putObjectParams)
        {
            var oRet = base.Scalar(sCommand, cmdType, putObjectParams);
            Fields.Clear();
            return (oRet);
        }

        public virtual object this[string Name]
        {
            get { return (Fields.ContainsKey(Name) ? Fields[Name] : null); }
            set { if (Fields.ContainsKey(Name)) Fields[Name] = value; else Fields.Add(Name, value); }
        }
    }
}
